import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import mpl_toolkits.axisartist as axisartist #导入坐标轴加工模块
import math

w = np.load('w.npy')
raw_data = pd.read_csv('./3.0a.csv')
positive_x = np.append(raw_data[raw_data['好瓜'] == 1][['密度', '含糖率']].values, np.ones(shape=(raw_data[raw_data['好瓜'] == 1][['密度', '含糖率']].values.shape[0], 1)), axis=1)
nagetive_x = np.append(raw_data[raw_data['好瓜'] == 0][['密度', '含糖率']].values, np.ones(shape=(raw_data[raw_data['好瓜'] == 0][['密度', '含糖率']].values.shape[0], 1)), axis=1)
positive_z = positive_x @ w
nagetive_z = nagetive_x @ w
print(positive_z, nagetive_z)

# 
plt.rcParams['font.sans-serif'] = 'SimHei' ## 设置中文显示
plt.rcParams['axes.unicode_minus'] = False
fig=plt.figure(figsize=(4,2)) #新建画布
ax=axisartist.Subplot(fig,111) #使用axisartist.Subplot方法创建一个绘图区对象ax
fig.add_axes(ax) #将绘图区对象添加到画布中

ax.axis[:].set_visible(False) #隐藏原来的实线矩形
 
ax.axis["x"]=ax.new_floating_axis(0,0,axis_direction="bottom") #添加x轴
ax.axis["y"]=ax.new_floating_axis(1,0,axis_direction="bottom") #添加y轴
 
ax.axis["x"].set_axisline_style("->",size=1.0) #给x坐标轴加箭头
ax.axis["y"].set_axisline_style("->",size=1.0) #给y坐标轴加箭头
ax.annotate(s='z' ,xy=(2*math.pi,0) ,xytext=(2*math.pi,0.1)) #标注x轴
ax.annotate(s='y' ,xy=(0,1.0) ,xytext=(-0.5,1.0)) #标注y轴
 
plt.xlim(-15, 15) #设置横坐标范围
plt.ylim(0, 2) #设置纵坐标范围
ax.set_xticks(range(-15, 16, 1)) #设置x轴刻度
ax.set_yticks([-1,1]) #设置y轴刻度

# sigmoid 函数 
sigmoid_x = np.linspace(-15, 15, 1000)
sigmoid_y = 1 / (1 + np.power(np.e, -sigmoid_x))
plt.plot(sigmoid_x, sigmoid_y, color="black") #描点连线

# z = wx
positive_dot = plt.scatter(positive_z, 1 / (1 + np.power(np.e, -positive_z)), c='red', label='正样本')
nagetive_dot = plt.scatter(nagetive_z, 1 / (1 + np.power(np.e, -nagetive_z)), c='blue', label='负样本')

# 
plt.legend(handles=[positive_dot, nagetive_dot])
plt.show() #出图
